import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class SellLuckdrawManageService {

  serviceUrls: any = {
    uploadFileUrl: '/common/upload/file', // 文件上传
    lotteryListUrl: '/activity/list', // 下单抽奖列表
    lotteryDeatilsUrl: '/activity/details', // 下单抽奖详情
    lotteryAddUrl: '/activity/save', // 下单抽奖新增
    lotteryUpdateUrl: '/activity/update', // 下单抽奖编辑
    lotteryRecordUrl: '/activityUserRecord/list', // 下单抽奖记录
    updateStatusUrl: '/activity/enable', // 下单抽奖list启用、禁用、删除

    exportActivityRecordUrl: '/activityUserRecord/getExcel' // 抽奖记录导出
  };

  constructor(public httpClient: HttpClient) { }

  /**
   * 文件上传
   * @param fileToUpload 
   * @returns 
   */
  uploadFileData(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "luckdraw");
    return this.httpClient.post(this.serviceUrls.uploadFileUrl, formData).toPromise();
  }

  /**
   * 下单抽奖列表
   * @param params 
   * @returns 
   */
  queryLotteryList(params: any) {
    return this.httpClient.post(this.serviceUrls.lotteryListUrl, params).toPromise();
  }

  /**
   * 下单抽奖列表
   * @param params 
   * @returns 
   */
  queryLotteryDetail(params: any) {
    return this.httpClient.post(this.serviceUrls.lotteryDeatilsUrl, params).toPromise();
  }

  /**
   * 下单抽奖新增
   * @param params 
   * @returns 
   */
  addLotteryItem(params: any) {
    return this.httpClient.post(this.serviceUrls.lotteryAddUrl, params).toPromise();
  }

  /**
   * 下单抽奖新增
   * @param params 
   * @returns 
   */
  updateLotteryItem(params: any) {
    return this.httpClient.post(this.serviceUrls.lotteryUpdateUrl, params).toPromise();
  }

  /**
   * 下单抽奖记录list
   * @param params 
   * @returns 
   */
  querylotteryRecord(params: any) {
    return this.httpClient.post(this.serviceUrls.lotteryRecordUrl, params).toPromise();
  }

  /**
   * 状态修改
   * @param params 
   * @returns 
   */
  updateStatusItem(params: any) {
    return this.httpClient.post(this.serviceUrls.updateStatusUrl, params).toPromise();
  }

  /**
   * 抽奖记录导出
   * @param params 
   * @returns 
   */
  exportActivityRecordData(params: any) {
    return this.httpClient.get(this.serviceUrls.exportActivityRecordUrl, { params, responseType: 'blob' }).toPromise();
  }
}



